<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <link href="css/allcss.css" rel="stylesheet" type="text/css"/>
        <link rel="shortcut icon"  href="image/icon6.ico" type="image/x-icon" /> 
        <title>complaint</title>
        <script src="./script/jquery.js" type="text/javascript"></script>
        <style>
            #op8{
                color:#00aeec;
            }
        </style>
    </head>
    <body>
        <div id="aside">
            <img id="icon" src="./image/icon6.png">
            <div id="p1">管理员界面</div>  
        </div>
        <div id="main">
            <div id="list"><div id="op1" class="options">全部预约</div><div  id="op2" class="options">未审核</div><div  id="op3" class="options">已审核</div>
                <div  id="op4" class="options">地点管理</div><div  id="op5" class="options">地点上新</div><div  id="op6" class="options">数据库管理</div>
                <div  id="op7" class="options">学生信用度</div><div  id="op8" class="options">申诉回复</div>
            </div>
            <div id="content">
            </div>
        </div>
        <script>
            const urlParams = new URLSearchParams(window.location.search);
            function query() {
                $.get("./Servlet/complainServlet", function (data, status) {
                    if (status) {
                        var datas = JSON.parse(data);
                        for (var i = 0; i < datas.length; i++) {
                            var complaintsDiv = document.createElement('div');
                            complaintsDiv.className = 'complaints';
                            var hint = document.createElement('div');
                            hint.className = 'hint';
                            hint.innerHTML = "请在右侧回复";
                            complaintsDiv.appendChild(hint);
                            var saDiv = document.createElement('div');
                            saDiv.className = 'studentAccount';
                            saDiv.innerHTML = "学生账号:  " + datas[i].sa;
                            complaintsDiv.appendChild(saDiv);
                            var ccDiv = document.createElement('div');
                            ccDiv.className = 'complaintContent';
                            ccDiv.innerHTML = "申诉内容:  " + datas[i].cc;
                            complaintsDiv.appendChild(ccDiv);
                            var crDiv = document.createElement('div');
                            crDiv.className = 'complaintReply';
                            crDiv.id = "crDiv" + datas[i].id;
                            if (datas[i].cr !== undefined) {
                                crDiv.innerHTML = "申诉回复:  " + datas[i].cr;
                            }
                            complaintsDiv.appendChild(crDiv);
                            var input = document.createElement('textarea');
                            input.className = 'complaintInput';
                            input.id = "input" + datas[i].id;
                            complaintsDiv.appendChild(input);
                            var button = document.createElement('button');
                            button.className = 'complaintButton';
                            button.innerHTML = '回复';
                            button.setAttribute("onclick", "add(event)");
                            button.setAttribute("value", datas[i].id);
                            complaintsDiv.appendChild(button);
                            ContainerDiv.appendChild(complaintsDiv);
                        }
                    }
                }
                );
            }
            query();
            var ContainerDiv = document.getElementById('content');
            function check() {
                if (position.value.length !== 0 && image.value.length !== 0)
                    button1.disabled = false;
                else
                    button1.disabled = true;
            }
            function add(event) {
                var id = event.target.value;
                var text = $('#input' + id);
                var crDivText = $('#crDiv' + id);
                $.get("./Servlet/replyServlet?complaintReply=" + text.val() + "&id=" + id, function (data, status) {
                    if (status) {
                        if (data !== "-1") {
                            alert("成功");
                            crDivText.html("申诉回复:  " + text.val());
                        } else
                            alert("失败");
                    }
                });
            }
        </script>
        <script src="./script/button.js" type="text/javascript"></script>
    </body>
</html>

